In [ ]:
import random
In [ ]:
f=open("CustomerDetails.csv","w+")
f.write("Account Number,name,age,aadhar,phone number,account type\n")   
# #this part of code should be run only once or else 
# all previous data will be erased
f.close()
In [ ]:
def createAccount():
    accountNum=""
    for i in range(10):                             #generation of acc.number
        j=str(random.randint(0,9))
        accountNum=accountNum+j    #concatenating randomly generated number to accountNum variable
                       
    name=input("enter name:")
    age=input("enter age:")
    aadhar=input("enter aadhar number:")               
    phno=input("enter mobile number:")
    accType=input("enter account type: Savings or Current?")
    details_values=[name.title().strip(),age,aadhar,phno,accType.title().strip()]
       
    
    with open("CustomerDetails.csv","a+") as file:
        file.write(accountNum)  #first we write account number followed by coma in file
        for i in details_values:
            file.write(","+str(i)) #then each elements in details_values are written to file,separetd by ","
        file.write("\n")          #goes to next line of file
    print("account created successfully!")
    print("your account Number is: ",accountNum)      #user o/p
In [ ]:
def editName(line):    #the line containing account number from the file is sent to fn
    
    
    oldName=(input("enter old name")).strip().title()
    newName=(input("enter new name")).strip().title()
    if oldName in line:         
        new_line=line.replace(oldName,newName)   #new name replaces old name in line
        with open("CustomerDetails.csv","a+") as file:
            file.write(new_line)       #adds new line to file
        with open("CustomerDetails.csv","r+") as file:
            a=file.readlines()     #gets all lines from file and stored in a list
        
        a.remove(line)    # from the list, the line with wrong name is removed
        
        with open("CustomerDetails.csv","w+") as file:
            file.writelines(a)             #the above list of lines is stored back into the file
            
        print("name updated")    #user o/p
    else:
        print("name doesnt match !")
In [ ]:
def editPhone(line):     #the line containing account number from the file is sent to fn
    oldph=(input("enter your phone no:"))
    newph=input("enter new phone number:")
    if oldph in line:
        new_line=line.replace(oldph,newph)
        with open("CustomerDetails.csv","a+") as file:
            file.write(new_line)
        with open("CustomerDetails.csv","r+") as file:
            a=file.readlines()
        
        a.remove(line)
        
        with open("CustomerDetails.csv","w+") as file:
            file.writelines(a)
            
        print("phone number updated")             #user o/p
    else:
        print("phone number doesnt match !")
In [ ]:
def editDetails():
    print("a.edit name")
    print("b.edit phone number")
    print("c.exit")
    option=input("enter your option:")
    if option=="a" or option=="b":             # only when a or b entered we ask for account number
        ac=input("enter account number")
        with open("CustomerDetails.csv","r+") as file:
            for line in file.readlines():
                if ac in line:                   #take each line from file and check for acc number
                    if option=="a":   #call functions based on user option
                        editName(line) 
                        break #so that rest of lines need not be checked as line containing acc.no is found        
                    elif option=="b":
                        editPhone(line)
                        break
                    else:
                        pass

            else :
                print("account number not found!")
        
    else:
        print("enter valid option")
In [ ]:
def loanEligibility():
    print("are you....")
    print("1.self employed")
    print("2.salaried")                  #ask for employment status

    choice=input("enter job option:")
    age=int(input("enter your age:"))
    income=int(input("enter your annual income:"))
    creditScore=int(input("enter your credit score:"))
    if choice=="1":
        if creditScore>=750 and 21<=age<=65 and income>=1500000:
            year=int(input("enter period of business coninuity:"))
            if year>=3:
                print("you are eligible for a loan!!")
            else:
                print("not eligible for loan")
        else:
            print("not eligible for loan")
    
    elif choice=="2":
        if 18<=age<=60 and creditScore>=750 and income>=180000:
            year=int(input("enter period of employment in years:"))
            if year>=1:
                print("you are eligible for a loan!")
            else:
                print("not eligible for loan")
        else:
            print("not eligible for loan")
    else:
        print("not a valid option")
                
In [ ]:
convRate_inr_usd=83.1
def inr_to_usd(amount):       #functions for rupee to dollars and back 
    serviceCharge=amount*0.01
    usd=(amount-serviceCharge)/convRate_inr_usd            #calculation
    print("amount recieved\t\t{} INR".format(amount))     #bill output for user
    print("\tservice charge:1%' of {} INR".format(amount))
    print("\t\t\t=","%.2f" % serviceCharge)
    print("converted amount:USD ","%.2f" % usd)
    print("\t\tconversion rate=","%.2f" % 1/convRate_inr_usd)

def usd_to_inr(amount):
    serviceCharge=amount*0.01
    rs=(amount-serviceCharge)*convRate_inr_usd            
    print("amount recieved\t\t{} USD".format(amount))
    print("\tservice charge:1%' of {} USD".format(amount))
    print("\t\t\t=","%.2f" % serviceCharge)
    print("converted amount:INR ","%.2f" % rs)
    print("\t\tconversion rate=","%.2f" % convRate_inr_usd)
    
In [ ]:
convRate_inr_aed=22.66                    
def inr_to_aed(amount):                  #functions for rupee to dirham and back 
    serviceCharge=amount*0.01
    aed=(amount-serviceCharge)/convRate_inr_aed
    print("amount recieved\t\t{} INR".format(amount))
    print("\tservice charge:1%' of {} INR".format(amount))
    print("\t\t\t=","%.2f" % serviceCharge)
    print("converted amount:AED ","%.2f" % aed)
    print("\t\tconversion rate=","%.2f" % 1/convRate_inr_aed)
def aed_to_inr(amount):
    serviceCharge=amount*0.01
    rs=(amount-serviceCharge)*convRate_inr_aed    
    print("amount recieved\t\t{} AED".format(amount))
    print("\tservice charge:1%' of {} AED".format(amount))
    print("\t\t\t=","%.2f" % serviceCharge)
    print("converted amount:INR","%.2f" % rs)
    print("\t\tconversion rate=","%.2f" % convRate_inr_aed)
    
In [ ]:
convRate_inr_euro=88.72
def inr_to_euro(amount):        #functions for rupee to euros and back 
    serviceCharge=amount*0.01
    euro=(amount-serviceCharge)/convRate_inr_euro
    print("amount recieved\t\t{} INR".format(amount))
    print("\tservice charge:1%' of {} INR".format(amount))
    print("\t\t\t=",serviceCharge)
    print("converted amount:EURO ",euro)
    print("\t\tconversion rate=","%.2f" % (1/convRate_inr_euro))
    
def euro_to_inr(amount):
    serviceCharge=amount*0.01
    rs=(amount-serviceCharge)*convRate_inr_euro          
    print("amount recieved\t\t{} EURO".format(amount))
    print("\tservice charge:1%' of {} EURO".format(amount))
    print("\t\t\t=","%.2f" % serviceCharge)
    print("converted amount:INR","%.2f" % rs)
    print("\t\tconversion rate=","%.2f" % convRate_inr_euro)
    
In [ ]:
def forex():
    print("1.INR <--> USD")
    print("2.INR <--> AED")
    print("3.INR<-->EURO")
    choice=input("enter your choice of conversion:")
    
    if choice=='1':
        print("conversions:")
        print("1.INR --> USD")                    
        print("2.USD --> INR")
        
        choice=input("please enter which way you need to convert")
        amt=int(input("enter amount to convert:"))
        print("*"*30)
        print("Receipt")
        print("*"*30)

        if choice=='1':
            inr_to_usd(amt)
        elif choice=='2':
            usd_to_inr(amt)
        else:
            print("enter valid option!")
    
    elif choice=='2': 
        print("conversions:")
        print("1.INR --> AED")
        print("2.AED --> INR")
        choice=input("please enter which way you need to convert:")
        amt=int(input("enter amount to convert:"))
        print("*"*30)
        print("Receipt")
        print("*"*30)

        if choice=='1':
            inr_to_aed(amt)
        elif choice=='2':
            aed_to_inr(amt)
        else:
            print("enter valid option!")
            
    elif choice=='3': 
        print("conversions:")
        print("1.INR --> EURO")
        print("2.EURO --> INR")
        choice=input("please enter which conversion you need")
        amt=int(input("enter amount to convert:"))
        print("*"*30)
        print("Receipt")
        print("*"*30)

        if choice=='1':
            inr_to_euro(amt)
            
        elif choice=='2':
            euro_to_inr(amt)           
        else:
            print("enter valid option!")
    
    else:
        print("enter a valid option!")
In [ ]:
while True:
    print("1.Create new account")                         #menu
    print("2.edit details")
    print("3.check eligibility for loan")
    print("4.Forex")
    print("5.exit")
    choice=input("enter your choice")
    if choice=='1':
        createAccount()
    elif choice=='2':
        editDetails()
    elif choice=='3':
        loanEligibility()
    elif choice=="4":
        forex()
    elif choice=='5':
        break
    else:
        print("invalid choice!")
1.Create new account
2.edit details
3.check eligibility for loan
4.Forex
5.exit
1.INR <--> USD
2.INR <--> AED
3.INR<-->EURO
conversions:
1.INR --> EURO
2.EURO --> INR
******************************
Receipt
******************************
amount recieved		5000000 INR
	service charge:1%' of 5000000 INR
			= 50000.0
converted amount:EURO  55793.50766456267
		conversion rate= 0.01
1.Create new account
2.edit details
3.check eligibility for loan
4.Forex
5.exit
1.INR <--> USD
2.INR <--> AED
3.INR<-->EURO
conversions:
1.INR --> EURO
2.EURO --> INR
******************************
Receipt
******************************
amount recieved		50000004 INR
	service charge:1%' of 50000004 INR
			= 500000.04000000004
converted amount:EURO  557935.1212804328
		conversion rate= 0.01
1.Create new account
2.edit details
3.check eligibility for loan
4.Forex
5.exit
account created successfully!
your account Number is:  3413841873
1.Create new account
2.edit details
3.check eligibility for loan
4.Forex
5.exit
In [ ]:
#analysis
def age_analysis():
    age20_30=0
    age30_40=0
    age40_50=0
    age50_60=0
    age60_70=0
    with open("CustomerDetails.csv","r+") as file_analysis:
        for line in file_analysis.readlines():
            if "name" in line:    #avoid the first line containing column headings
                pass
            else:
                line_split=line.strip().split(",")            
                custmr_age=int(line_split[2])/10 
         #the element at index2 will be age because thats the order we saved details                                #converted to int and divided by 10 for various test cases
                match int(custmr_age):    #typecast again to convert floats resulting from division
                    case 2:                
                        age20_30+=1
                    case 3:
                        age30_40+=1 #used python switch-case equivalent
                    case 4:            #counters of various age groups are incremented accordingly
                        age40_50+=1
                    case 5:
                        age50_60+=1
                    case 6:
                        age60_70+=1
                    case default:
                        print("error")

    age_analysis={
                "20-30":age20_30,
                "30-40":age30_40,
                "40-50":age40_50,
                "50-60":age50_60,
                "60-70":age60_70
                }
    max_count=max(age_analysis.values())   #getting maximum values
    
    ages=[]
    print("AGE ANALYSIS")
    print("*"*30)
    for i in age_analysis.items():   #i will be a tuple 
        for j in i:     # j is an element of the tuple
            print(j,end="\t")
            if j==max_count:#if j is the max value, we get the key of j by using index of tuple i 
                ages.append(i[0])  #storing in list,incase there are multiple max age groups
        print("\n")
    print("*"*30)

    print("most customers are present in the  age group ",end=" ")
    for i in ages:   #i will be a tuple 
        print(i,end=" ")
           
In [ ]:
age_analysis()
AGE ANALYSIS
******************************
20-30	4	

30-40	4	

40-50	2	

50-60	2	

60-70	1	

******************************
most customers are present in the  age group  20-30 30-40